<?php


class UserMapper
{
    private $adapter;

    public function __construct(StorageAdapter $adapter)
    {
        $this->adapter = $adapter;
    }

    public function findById($id)
    {
        $result = $this->adapter->find($id);

        if ($result === null) {
            throw new Exception('user not found');
        }
        return $this->mapRowToUser($result);
    }
    private function mapRowToUser($row)
    {
        return User::fromState($row);
    }
}